package com.gqz.aircraftwar.mvp.model.buff

import android.graphics.*
import android.util.Log.i
import com.gqz.aircraftwar.App
import com.gqz.aircraftwar.App.Companion.paint
import com.gqz.aircraftwar.R
import com.gqz.aircraftwar.mvp.model.aircraft.Aircraft
import com.gqz.aircraftwar.util.MyEnum

/**
 * 增益类
 *
 * @author gqz
 * @data 2020/4/2
 */

abstract class Buff {


    private val TAG: String = "Buff-->"
    var bmp: Bitmap
    var duration = 10 * 1000//10s
    var isOver = false//增益时间是否结束
    var added = false//是否已添加到飞机，true则不继续绘制
    var type = MyEnum.BuffType.Null

    var pos = PointF(0f, 0f)
    var speedx = 3f
    var speedy = 4f

    init {
        bmp = BitmapFactory.decodeResource(App.instance.resources, R.drawable.buff)
        bmp = Bitmap.createScaledBitmap(
            bmp, (bmp.width.toFloat() * 0.4f).toInt(), (bmp.height.toFloat() * 0.4f).toInt(), false
        )
        speedx += Math.random().toFloat() / 2
        speedy += Math.random().toFloat()
    }

    companion object {
        var Null = NullBuff()
    }

    abstract fun buff(aircraft: Aircraft)
    abstract fun relieveBuff(aircraft: Aircraft)

    fun move() {
        if (pos.x <= 0 || pos.x >= App.surfaceW - bmp.width) {
            speedx *= -1
        }
        if (pos.y <= 0 || pos.y >= App.surfaceH - bmp.height) {
            speedy *= -1
        }
        pos.x += speedx
        pos.y += speedy
    }

    fun hit(aircraft: Aircraft) {
        var rect = RectF(pos.x, pos.y, pos.x + bmp.width, pos.y + bmp.height)
        var isIntersect = rect.intersect(aircraft.getRect())
        if (isIntersect) {
            aircraft.addBuff(this)
            added = true
            i(TAG, "hit--> player got a buff")
        }
    }

    fun draw(canvas: Canvas) {
        canvas.drawBitmap(bmp, pos.x, pos.y, paint)
    }
}

class NullBuff : Buff() {
    override fun relieveBuff(aircraft: Aircraft) {
    }

    override fun buff(aircraft: Aircraft) {
    }
}

//飞机属性增益

/**
 * 攻速增益
 */
class AtkSpeedBuff : Buff() {
    override fun relieveBuff(aircraft: Aircraft) {
        aircraft.attackSpeed -= 2
        aircraft.refreshAtkInterval()
    }

    init {
        type = MyEnum.BuffType.AtkSpeed
    }

    override fun buff(aircraft: Aircraft) {
        aircraft.attackSpeed += 2
        aircraft.refreshAtkInterval()
    }

}
/**
 * 防御增益
 */
/**
 * 生命增益
 */

//子弹属性增益
/**
 * 伤害增益
 */
/**
 * 速度增益
 */

//攻击模式增益

/**
 * 散射增益
 */
class ScatteringBuff : Buff() {
    init {
        type = MyEnum.BuffType.Scattering
    }

    override fun buff(aircraft: Aircraft) {
        aircraft.attackSpeed *= 3
        aircraft.refreshAtkInterval()
    }

    override fun relieveBuff(aircraft: Aircraft) {
        aircraft.attackSpeed /= 3
        aircraft.refreshAtkInterval()
    }

}
/**
 * 电磁炮增益
 */
/**
 * 激光炮增益
 */
